package com.example.spb_rabbitmq2.controller;

import com.example.spb_rabbitmq2.services.MessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: climber zheng
 * @Desc:
 * @create: 2023-10-20 21:27
 **/
@RestController
@Slf4j
public class MessageController {
    @Autowired
    MessageService messageService;

    @GetMapping("sendInSimpleModel")
    public String sendMessageInSimpleModel(String message){
        messageService.sendInSimpleModel(message);
        return "succ";
    }
//the value of routeKey must be queue.log or queue.data
//    http://localhost:8081/sendInRouterModel?message=hello&routeKey=queue.log
//    http://localhost:8081/sendInRouterModel?message=hello&routeKey=queue.data
    @GetMapping("sendInRouterModel")
    public String sendMessageInRouterModel(String message,String routeKey){
        messageService.sendInRouterModel(message,routeKey);
        return "succ";
    }

//http://localhost:8081/sendInSubscribeModel?message=hello
    @GetMapping("sendInSubscribeModel")
    public String sendMessageToFanout(String message){
        messageService.sendToFanoutExchange(message);
        return "succ";
    }

//    通配符模式
//    测试的时候使用两条
//    http://localhost:8081/sendMessageToTopic?message=hello&routeKey=data.queue.orange
//    http://localhost:8081/sendMessageToTopic?message=hello&routeKey=log.queue.red
    @GetMapping("sendInMatchModel")
    public String sendMessageToTopic(String routeKey,String message){
        messageService.sendToTopic(routeKey,message);
        return "succ";
    }





}
